export default {

    
    promise() {
        new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/1",
                success(data) {
                    resolve(data);
                }
            });
        }).then(arr => {
            return new Promise(resolve => {
                $.ajax({
                    type: "GET",
                    url: "/api/test/2",
                    success(data) {
                        arr = [...arr, ...data];
                        resolve(arr);
                    }
                });
            });
        }).then(arr => {
            return new Promise(resolve => {
                $.ajax({
                    type: "GET",
                    url: "/api/test/3",
                    success(data) {
                        arr = [...arr, ...data];
                        resolve(arr);
                    }
                });
            });
        }).then(console.log);
    },
    *gen() {
        const a = yield new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/1",
                success: resolve
            });
        });
        const b = yield new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/2",
                success: resolve
            });
        });
        const c = yield new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/3",
                success: resolve
            });
        });
        return [...a, ...b, ...c]
    },
    async asyncFn() {
        const a = await new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/1",
                success: resolve
            });
        });
        const b = await new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/2",
                success: resolve
            });
        });
        const c = await new Promise(resolve => {
            $.ajax({
                type: "GET",
                url: "/api/test/3",
                success: resolve
            });
        });
        return [...a, ...b, ...c]
    }
}

// generator函数 生成器
// function* gen() {
//     console.log("in");
//     const a = yield 1;
//     console.log(a);
//     const b = yield 2;
//     console.log(b);
//     const c = yield 3;
//     console.log(c);
//     return a + b + c
// }
// const it = gen();
// console.log(it.next());
// console.log(it.next(10));
// console.log(it.next(20));
// console.log(it.next(30));
// function* gen1() {
//     console.log("hello");
//     yield function test() { }
//     console.log(1);
//     yield [1, 2, 3]
//     console.log(2);
//     console.log(1 + (yield 1));
// }
// const it1 = gen1();
// console.log(it1.next());
// console.log(it1.next());
// console.log(it1.next());
// console.log(it1.next(10));
// let data = new Promise(resolve => {
//     resolve(1)
// }).then(data => {
//     console.log(data);
//     return 2
// }).then(data => {
//     console.log(data);
//     return 3
// });
// console.log(data);
// console.log(data.then(console.log));
// async function login({ username = 1, password = 1 } = {}) {
//     let data = await new Promise(resolve => {
//         $.ajax({
//             type: "GET",
//             url: "/api/users/login",
//             data: { username, password },
//             success: resolve
//         });
//     });
//     console.log(data);//{status: false, userArr: Array(5)}
//     return data
// }
// let a = login();
// console.log(a);//promise
// a.then(console.log);//{status: false, userArr: Array(5)}


console.log(`2132456789`);